import {getOne} from "@/api/system/config/configBase";


const config = {
  state:{
    menuTopBg: localStorage.getItem('menuTopBg') || '',//顶部菜单栏背景色
    mainColor:localStorage.getItem('mainColor')||'',//主题色
  },
  mutations:{
    SET_menuTopBg: (state, menuTopBg) => {
      localStorage.setItem('menuTopBg',menuTopBg)
      state.menuTopBg = menuTopBg
    },
    SET_mainColor: (state, mainColor) => {
      localStorage.setItem('mainColor',mainColor)
      state.mainColor = mainColor
    },
  },
  actions:{
    // 获取用户信息
    getConfigInfo({commit}){
      return new Promise((resolve,reject)=>{
        getOne().then(res => {
          let config=res.data;
          let menuTopBg=config.configTheme.menuTopBg;


          commit('SET_mainColor', menuTopBg)
          commit('SET_menuTopBg', menuTopBg)


          resolve(config)
        }).catch(error => {
          console.log(error)
          reject(error)
        })




      })
    }
  }
}

export default config
